package com.demo.main.service;

import com.demo.main.dao.BaseDao;
import com.demo.main.utils.PaginationUtil;

import java.util.List;

public class BaseService<T, E> {
    private final BaseDao<T, E> baseDaoDao;

    public BaseService(BaseDao<T, E> baseDaoDao) {
        this.baseDaoDao = baseDaoDao;
    }

    public List<T> findAllByDesc() {
        return baseDaoDao.selectAllByDesc();
    }

    public List<T> findAll() {
        return baseDaoDao.selectAll();
    }

    public List<T> findPagination(Integer pageNum) {
        return baseDaoDao.selectPagination(pageNum);
    }

    public List<T> findPagination() {
        return baseDaoDao.selectPagination(1);
    }

    public List<T> findSelectivePagination(T entity, Integer pageNum) {
        return baseDaoDao.selectSelectivePagination(pageNum, entity);
    }

    public Integer findCount() {
        return baseDaoDao.selectCount();
    }

    public Integer findPageCount() {
        return PaginationUtil.pageCount(baseDaoDao.selectCount());
    }

    public Integer findPageCountByCondition(T entity) {
        return PaginationUtil.pageCount(baseDaoDao.selectCountByCondition(entity));
    }

    public T findOneById(E id) {
        return baseDaoDao.selectOneById(id);
    }

    public List<T> findById(E id) {
        return baseDaoDao.selectById(id);
    }

    public List<T> findByCondition(T entity) {
        return baseDaoDao.selectByCondition(entity);
    }

    public T findOneByCondition(T entity) {
        return baseDaoDao.selectOneByCondition(entity);
    }

    public void addOne(T entity) {
        baseDaoDao.insertOne(entity);
    }

    public void deleteById(E id) {
        baseDaoDao.deleteById(id);
    }

    public void updateById(T entity) {
        baseDaoDao.updateById(entity);
    }

    public void batchDeleteByIds(List<?> ids) {
        baseDaoDao.batchDeleteByIds(ids);
    }
}
